package com.javafactroy.kunlong.bip.icp.ftpclient.dxp;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import com.javafactroy.kunlong.bip.icp.ftpclient.base.FtpTemplate;
import java.io.ByteArrayInputStream;
import java.io.File;

@Data
@Component
@Slf4j
public class DxpFtpTemplate extends FtpTemplate {
    private static ByteArrayInputStream biok;

    public DxpFtpTemplate() {
        biok = new ByteArrayInputStream("ok".getBytes());

    }

    public void upload(String path, String filename, byte[] bytes) {
        getFtp().upload(path, filename, new ByteArrayInputStream(bytes));
        log.info(filename);
        uploadOk(path, filename);
    }
    public void download(String path, String filename, File file) {
        getFtp().download(path,filename,file);
    }

    private void uploadOk(String path, String filename) {
        filename += ".OK";
        if (biok == null) {
            biok = new ByteArrayInputStream("ok".getBytes());
        }
        getFtp().upload(path, filename, biok);
        log.info("uploadOk={}", filename);

    }
}
